<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>客户端管理列表</title>
    <jsp:include page="/WEB-INF/view/commons/css.jsp" />
</head>
<body >
<div id="main-container" class="container-fluid">
    <form action="bizClient/dolist" method="post" name="searchForm" id="searchForm" role="form" class="form-horizontal">
            <div class="form-group">
                    <label class="col-sm-1 control-label">客户端编号：</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" name="clientId" value="${entity.clientId}" placeholder="客户端编号">
                    </div>
                    <label class="col-sm-1 control-label">激活码：</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" name="activationCode" value="${entity.activationCode}" placeholder="激活码">
                    </div>
            </div>
            <div class="form-group">
                    <label class="col-sm-1 control-label">激活时间：</label>
                    <div class="col-md-4">
                        <div class="input-group">
                           <input type="text"  class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', maxDate:'#F{$dp.$D(\'endActivationTime\')}'})" id="beginActivationTime" name="beginActivationTime" value="${searchEntity.beginActivationTime}" placeholder="开始时间" />
                			至 <input type="text"  class="span1 Wdate" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd', minDate:'#F{$dp.$D(\'beginActivationTime\')}'})" id="endActivationTime" name="endActivationTime" value="${searchEntity.endActivationTime}" placeholder="结束时间" />
                        </div>
                    </div>
                    <label class="col-sm-1 control-label">激活状态：</label>
                    <div class="col-md-4">
                        <d:select clazz="selectpicker" list="${activationStatusList}" name="activationStatus" id="selorgtype" selected="${activationStatus}"></d:select>
                    </div>
            </div>
        <div class="form-group">
            <div class="col-md-4">
                 <button id="searchBtn" type="button" class="btn btn-sm btn-info"><i class="fa fa-search"></i> 搜索</button>
                 <button type="button" class="btn btn-sm btn-success" data-title="上传激活码" onclick="show_important();"><i class="glyphicon glyphicon-upload"></i>上传激活码</button>
                 <button type="button" class="btn btn-sm btn-warning" data-title="注销" onclick="onCancel();"><i class="glyphicon glyphicon-remove-circle"></i>注销</button>
                 <button type="button" class="btn btn-sm btn-danger" data-title="删除" onclick="onDelete();"><i class="fa fa-trash"></i>删除</button>
            </div>
        </div>
    </form>
    
    <form id= "exportexcalform" method=post action="bizClient/codes/export" target="_blank" >
	</form>
    <%-- <div class="row">
        <div class="col-md-10">
            <p>
                <shiro:hasPermission name="BIZ_CLIENT:add">
                    <button type="button" data-url="bizClient/create" class="btn btn-sm btn-success link_add" data-title="新增客户端管理"><i class="fa fa-plus"></i> 新增</button>
                </shiro:hasPermission>
                <shiro:hasPermission name="BIZ_CLIENT:edit">
                    <button type="button" data-url="bizClient/edit" class="btn btn-sm btn-primary link_edit" data-title="编辑客户端管理"><i class="fa fa-edit"></i> 修改</button>
                </shiro:hasPermission>
                <shiro:hasPermission name="BIZ_CLIENT:delete">
                    <button type="button" data-url="bizClient/delete" class="btn btn-sm btn-danger link_del"><i class="fa fa-trash"></i> 删除</button>
                </shiro:hasPermission>
                <shiro:hasPermission name="BIZ_CLIENT:view">
                    <button type="button" data-url="bizClient/info" class="btn btn-sm link_info" data-title="客户端管理详情"><i class="fa fa-book"></i> 详情</button>
                </shiro:hasPermission>
            </p>
        </div>
    </div> --%>

    <table id="table_data" class="table table-striped table-bordered table-hover">
        <thead>
        <tr>
            <th class="center td-checkbox" width="5%">
                <label><input type="checkbox" class="check-all ace" data-tableid="table_data" /><span class="lbl"></span></label>
            </th>
            <th width="10%">序号</th>
            <th width="10%">客户端编号</th>
            <th width="10%">激活码</th>
            <th width="10%">激活时间</th>
            <th width="10%">最近使用时间</th>
            <th width="10%">状态</th>
        </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
</div>
<!-- 返回顶部  -->
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>
<!-- script start -->
<jsp:include page="/WEB-INF/view/commons/js.jsp" />
<script type="text/javascript">
    $(document).ready(function(e) {
        var table = $("#table_data").dataTable({
            ajax: function(data, callback, settings){
                tableAjax($("#searchForm"),data, callback, settings);
            },
            //列表表头字段
            columns: [
                mainConfig.checkboxColumn,
                {"data": "index",
				"render" :function(data,type,row,meta){
					var startIndex = meta.settings._iDisplayStart;
					return startIndex+meta.row+1;
				},
				orderable:false
				},
                { "data": "clientId",name:"client_id",orderable:false },
                { "data": "activationCode",name:"activation_code",orderable:false },
                { "data": "activationTimeStr",name:"activation_time" },
                { "data": "lastUserTimeStr",name:"last_user_time" },
                { "data": "activationStatusStr",name:"activation_status",orderable:false }
        ]
    }).api();

        //查询条件
        $("#searchForm").submit(function(){
            table.ajax.reload();
            return false;
        });
    });
    
    function show_important(id){
        layer.prompt({
            formType: 2,
            value: "",
            title: "请输入激活码",
            area: ['600px', '350px']
        }, function(value, indexParent, elem) {
            $.ajax({
                url: "bizClient/codes/check",
                dataType: "json",
                type: "POST",
                data: {
                	codes: value
                },
                success: function (res) {
                	var data = res.data;
                    if(res.success){
                        layer.open({
                   		  	title: '消息提示',
                   		  	content: "本次导入"+ data.successCount + "条符合规则," + data.exitCount + "条记录已存在;" + data.errCount + "条记录无效,点击<a onclick='onExport();' style='cursor:pointer;'>《导入记录》</a>可下载详细的导入记录</br>请再次确认是否将有效激活码导入?",
                    		btn:["确定","取消"],
                    		yes:function(index, layero){
                    			if(data.successCount == 0){
                    				layer.msg('没有可以导入的激活码', {
                   	           		  icon: 5,
                   	           		  time: 2000 //2秒关闭（如果不配置，默认是3秒）
                   	           		}, function(){
                   	           			
                   	           		}); 
                    			}else{
                    				importCodes(index, indexParent);
                    			}
                    		},
                    		btn2:function(index, layero){
                    		}
                   		});
                    }else{
                        layer.alert(data.msg);
                    }
                }
            });
        });
    }
    
    //导入激活码
    function importCodes(index,indexParent){
    	$.ajax({
    		url: "bizClient/codes/import",
    		dataType: "json",
            type: "POST",
            success: function(res){
            	layer.close(index);
            	layer.close(indexParent);
            	$("#searchForm").submit();
            	layer.msg('导入激活码成功', {
           		  icon: 1,
           		  time: 2000 //2秒关闭（如果不配置，默认是3秒）
           		}, function(){
           			
           		}); 
            }
    	});
    }
    
    // 导出激活码校验结果
    function onExport(){
    	$("#exportexcalform").submit();
    }
    
    //删除
    function onDelete(){
    	var arr = $(".data-item:checked");
        if(arr.length == 0){
            layer.alert("未选择记录");
            return;
        }
        // 判断是否可以被删除
       	var flag = true;
        arr.each(function(n, item){
            var activationStatus = $(item).attr("data-status");
            if(activationStatus != 1){  //判断是否是未激活状态，不是未激活状态不可删除数据
            	flag = false;
            	return false;
            }
        });
        if(!flag){
        	layer.open({
       		  title: "提示",
       		  content: "请选择未激活的记录"
       		});
        	return;
        }
        var ids = getCheckedValues(arr, {});
        if(!ids){
            return;
        }
        var url = "bizClient/delete";
        url += "/" + ids.join(',');
    	layer.confirm("确定对选中的记录进行删除操作吗？", function(index) {
            layer.close(index);
            $.ajax({
                url: url,
                type: "DELETE",
                dataType: "json",
                success: function (data) {
                    if(data.success){
                        $("#searchForm").submit();
                    }else{
                        layer.alert(data.msg);
                    }
                }
            });
        });
    }
    
    //注销
    function onCancel(){
    	var arr = $(".data-item:checked");
        if(arr.length == 0){
            layer.alert("未选择记录");
            return;
        }
     // 判断是否可以被注销
       	var flag = true;
        arr.each(function(n, item){
            var activationStatus = $(item).attr("data-status");
            if(activationStatus != 3){  //判断是否是已激活状态，已激活状态才可以注销操作
            	flag = false;
            	return;
            }
        });
        if(!flag){
        	layer.open({
       		  title: "提示",
       		  content: "请选择已激活的记录"
       		});
        	return;
        }
        var ids = getCheckedValues(arr, {});
        if(!ids){
            return;
        }
        var url = "bizClient/cancel";
        url += "/" + ids.join(',');
        layer.confirm("确定对选中的记录进行注销操作吗？", function(index) {
            layer.close(index);
            $.ajax({
                url: url,
                type: "POST",
                dataType: "json",
                success: function (data) {
                    if(data.success){
                        $("#searchForm").submit();
                    }else{
                        layer.alert(data.msg);
                    }
                }
            });
        });
    }
    
</script>
<!-- script end -->
</body>
</html>